package edu.cmu.cs.erl.pltests;

import org.junit.Assert;
import org.junit.Test;

import jp.ac.kobe_u.cs.prolog.lang.JavaObjectTerm;
import jp.ac.kobe_u.cs.prolog.lang.Predicate;
import jp.ac.kobe_u.cs.prolog.lang.PrologControl;
import jp.ac.kobe_u.cs.prolog.lang.Term;
import jp.ac.kobe_u.cs.prolog.lang.VariableTerm;
import edu.cmu.cs.erl.rules.PRED_stringToBoolTest_2;

public class StringToBoolean {
	@Test
	public void upper() {
		PrologControl control = new PrologControl();
		Predicate pred = new PRED_stringToBoolTest_2();
		VariableTerm returnValue = new VariableTerm();
		Term[] termArgs = new Term[]{new JavaObjectTerm("Hello World!"), returnValue};
		
		if (control.execute(pred, termArgs)) {
			JavaObjectTerm object = (JavaObjectTerm)returnValue.dereference();
			System.out.println("Got back a " + object.object().toString());
			Assert.assertEquals("UPPER", object.object().toString());
		}
		else{
			System.out.println("Failed");
		}

	}
	
	@Test
	public void lower() {
		PrologControl control = new PrologControl();
		Predicate pred = new PRED_stringToBoolTest_2();
		VariableTerm returnValue = new VariableTerm();
		Term[] termArgs = new Term[]{new JavaObjectTerm("hello world!"), returnValue};
		
		if (control.execute(pred, termArgs)) {
			JavaObjectTerm object = (JavaObjectTerm)returnValue.dereference();
			System.out.println("Got back a " + object.object().toString());
			Assert.assertEquals("lower", object.object().toString());
		}
		else{
			System.out.println("Failed");
		}

	}

	public static boolean strToBool(String str){
		return Character.isUpperCase(str.charAt(0));
	}	
}
